package com.rmt.www.action;

import java.util.List;
import com.opensymphony.xwork2.ActionSupport;
import com.rmt.www.constant.ArtifactType;
import com.rmt.www.constant.ChangeControlActionType;
import com.rmt.www.service.AdminManageChangeService;
import com.rmt.www.vo.DesignArtifactRequest;
import com.rmt.www.vo.FeatureArtifactRequest;
import com.rmt.www.vo.ImplementationArtifactRequest;
import com.rmt.www.vo.RequirementArtifactRequest;
import com.rmt.www.vo.TestArtifactRequest;


public class ProcessRequestAction extends ActionSupport{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private int pid;
	private String pname;
	private int rid;
	private String perf;
	private String artifacttype;

	
	private AdminManageChangeService adminManageChangeService;
	
	private List<FeatureArtifactRequest> featureArtifactRequestList;
	private List<RequirementArtifactRequest> requirementArtifactRequestList;
	private List<DesignArtifactRequest> designArtifactRequestList;
	private List<ImplementationArtifactRequest> implementationArtifactRequestList;
	private List<TestArtifactRequest> testArtifactRequestList;

	public int getRid() {
		return rid;
	}

	public void setRid(int rid) {
		this.rid = rid;
	}

	
	public String getPerf() {
		return perf;
	}

	public void setPerf(String perf) {
		this.perf = perf;
	}

	public String getPname() {
		return pname;
	}

	public void setPname(String pname) {
		this.pname = pname;
	}


	public int getPid() {
		return pid;
	}

	public void setPid(int pid) {
		this.pid = pid;
	}

	
	
	public String execute(){
		
		if (artifacttype.equalsIgnoreCase(ArtifactType.DESIGN)) {
			if (perf.equalsIgnoreCase(ChangeControlActionType.ACCEPT)) {
				adminManageChangeService.acceptDesignRequest(rid);
			} else if (perf.equalsIgnoreCase(ChangeControlActionType.DECLINE)) {
				adminManageChangeService.declineDesignRequest(rid);
			} else if (perf.equalsIgnoreCase(ChangeControlActionType.IGNORE)) {
				//ignore it
				//Do nothing
			} else {
				try {
					throw new Exception("error action");
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		} else if (artifacttype.equalsIgnoreCase(ArtifactType.FEATURE)) {
			if (perf.equalsIgnoreCase(ChangeControlActionType.ACCEPT)) {
				adminManageChangeService.acceptFeatureRequest(rid);
			} else if (perf.equalsIgnoreCase(ChangeControlActionType.DECLINE)) {
				adminManageChangeService.declineFeatureRequest(rid);
			} else if (perf.equalsIgnoreCase(ChangeControlActionType.IGNORE)) {
				//ignore it
				//Do nothing
			} else {
				try {
					throw new Exception("error action");
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		} else if (artifacttype.equalsIgnoreCase(ArtifactType.REQUIREMENT)) {
			if (perf.equalsIgnoreCase(ChangeControlActionType.ACCEPT)) {
				adminManageChangeService.acceptRequirementRequest(rid);
			} else if (perf.equalsIgnoreCase(ChangeControlActionType.DECLINE)) {
				adminManageChangeService.declineRequirementRequest(rid);
			} else if (perf.equalsIgnoreCase(ChangeControlActionType.IGNORE)) {
				//ignore it
				//Do nothing
			} else {
				try {
					throw new Exception("error action");
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		} else if (artifacttype.equalsIgnoreCase(ArtifactType.IMPLEMENTATION)) {
			if (perf.equalsIgnoreCase(ChangeControlActionType.ACCEPT)) {
				adminManageChangeService.acceptImplRequest(rid);
			} else if (perf.equalsIgnoreCase(ChangeControlActionType.DECLINE)) {
				adminManageChangeService.declineImplRequest(rid);
			} else if (perf.equalsIgnoreCase(ChangeControlActionType.IGNORE)) {
				//ignore it
				//Do nothing
			} else {
				try {
					throw new Exception("error action");
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		} else if (artifacttype.equalsIgnoreCase(ArtifactType.TESTCASE)) {
			if (perf.equalsIgnoreCase(ChangeControlActionType.ACCEPT)) {
				adminManageChangeService.acceptTestCaseRequest(rid);
			} else if (perf.equalsIgnoreCase(ChangeControlActionType.DECLINE)) {
				adminManageChangeService.declineTestCaseRequest(rid);
			} else if (perf.equalsIgnoreCase(ChangeControlActionType.IGNORE)) {
				//ignore it
				//Do nothing
			} else {
				try {
					throw new Exception("error action");
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		
		featureArtifactRequestList = adminManageChangeService.getProjectFeatureRequests(pid);
		requirementArtifactRequestList = adminManageChangeService.getProjectRequirementRequest(pid);
		designArtifactRequestList = adminManageChangeService.getProjectDesignRequests(pid);
		implementationArtifactRequestList = adminManageChangeService.getProjectImplementation(pid);
		testArtifactRequestList = adminManageChangeService.getProjectTestCase(pid);
		
		pname = adminManageChangeService.getProjectName(pid);
		return "success";
	}

	public String getArtifacttype() {
		return artifacttype;
	}

	public void setArtifacttype(String artifacttype) {
		this.artifacttype = artifacttype;
	}

	public AdminManageChangeService getAdminManageChangeService() {
		return adminManageChangeService;
	}

	public void setAdminManageChangeService(
			AdminManageChangeService adminManageChangeService) {
		this.adminManageChangeService = adminManageChangeService;
	}

	public List<FeatureArtifactRequest> getFeatureArtifactRequestList() {
		return featureArtifactRequestList;
	}

	public void setFeatureArtifactRequestList(
			List<FeatureArtifactRequest> featureArtifactRequestList) {
		this.featureArtifactRequestList = featureArtifactRequestList;
	}

	public List<RequirementArtifactRequest> getRequirementArtifactRequestList() {
		return requirementArtifactRequestList;
	}

	public void setRequirementArtifactRequestList(
			List<RequirementArtifactRequest> requirementArtifactRequestList) {
		this.requirementArtifactRequestList = requirementArtifactRequestList;
	}

	public List<DesignArtifactRequest> getDesignArtifactRequestList() {
		return designArtifactRequestList;
	}

	public void setDesignArtifactRequestList(
			List<DesignArtifactRequest> designArtifactRequestList) {
		this.designArtifactRequestList = designArtifactRequestList;
	}

	public List<ImplementationArtifactRequest> getImplementationArtifactRequestList() {
		return implementationArtifactRequestList;
	}

	public void setImplementationArtifactRequestList(
			List<ImplementationArtifactRequest> implementationArtifactRequestList) {
		this.implementationArtifactRequestList = implementationArtifactRequestList;
	}

	public List<TestArtifactRequest> getTestArtifactRequestList() {
		return testArtifactRequestList;
	}

	public void setTestArtifactRequestList(
			List<TestArtifactRequest> testArtifactRequestList) {
		this.testArtifactRequestList = testArtifactRequestList;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}
}
